package cn.lijiguo.concurrency.part1.ch05;

import java.util.stream.IntStream;

/**
 * ThreadJoin2
 *
 * @author lijiguo
 * @date 2019/12/13 13:18
 */
public class ThreadJoin2 {

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            IntStream.range(1, 100).forEach(i -> {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + ":" + i);
            });
        });

        t1.start();
        t1.join(100, 10);

        System.out.println("All tasks done.");
        IntStream.range(1, 100).forEach(i -> {
            System.out.println(Thread.currentThread().getName() + ":" + i);
        });
    }
}
